%%% Calculate Static Gains
rng(17)

%%% UNCOMMENT BELOW TWO LINES FOR NEAR AUTARKY COUNTERFACTUAL IN T11
import_tariff_initial = 4;
counterfactuals = [1.538];

%%% COMMENT ABOVE AND UNCOMMENT BELOW FOR HALF TRADE COST COUNTERFACTUAL IN
%%% T11
% import_tariff_initial = 1.538;
% counterfactuals = [1.269];


results = [];

for import_tariff_counterfactual=counterfactuals

wage_gains_tracker_US = 0;
wage_gains_tracker_OECD = 0;
consumption_gains_tracker_US = 0;
consumption_gains_tracker_OECD = 0;

for repeats = 1:1:10
    
params = [0.1207	0.0296	0.1584	1.538	7.108	0.938];
max_year = 350;
import_tariff = import_tariff_initial;

[wage_levels, wage_levels_counterfactual, real_consumption, real_consumption_counterfactual] = steady_state_simulation_static_gains(params, max_year, import_tariff, import_tariff_counterfactual);

if import_tariff_counterfactual < import_tariff
static_wage_gains = wage_levels_counterfactual./wage_levels;

wage_gains_US = mean(static_wage_gains(end-50:end,1))
wage_gains_OECD = mean(static_wage_gains(end-50:end,2))

static_consumption_gains = real_consumption_counterfactual./real_consumption;

consumption_gains_US = mean(static_consumption_gains(end-50:end,1))
consumption_gains_OECD = mean(static_consumption_gains(end-50:end,2))
else

static_wage_gains = wage_levels./wage_levels_counterfactual;

wage_gains_US = mean(static_wage_gains(end-50:end,1))
wage_gains_OECD = mean(static_wage_gains(end-50:end,2))

static_consumption_gains = real_consumption./real_consumption_counterfactual;

consumption_gains_US = mean(static_consumption_gains(end-50:end,1))
consumption_gains_OECD = mean(static_consumption_gains(end-50:end,2))
end

wage_gains_tracker_US = wage_gains_tracker_US+wage_gains_US;
wage_gains_tracker_OECD = wage_gains_tracker_OECD+wage_gains_OECD;
consumption_gains_tracker_US = consumption_gains_tracker_US+consumption_gains_US;
consumption_gains_tracker_OECD = consumption_gains_tracker_OECD+consumption_gains_OECD;

end

wage_gains_temp_US = wage_gains_tracker_US./repeats;
wage_gains_temp_OECD = wage_gains_tracker_OECD./repeats;
consumption_gains_temp_US = consumption_gains_tracker_US./repeats;
consumption_gains_temp_OECD = consumption_gains_tracker_OECD./repeats;

results = [results; import_tariff_counterfactual wage_gains_temp_US wage_gains_temp_OECD; ...
    import_tariff_counterfactual consumption_gains_temp_US consumption_gains_temp_OECD];

end

%save('static_gains_half_trade_costs.mat','results');
save('static_gains_near_autarky.mat','results');